//定义store
import { defineStore } from 'pinia'
import { ref } from 'vue'
export const useTokenStore = defineStore('token', () => {
    //定义状态的内容

    //响应式变量
    const token = ref('')

    const auth = ref(-1)

    //定义一个函数,修改token的值
    const setToken = (newToken) => {
        console.log(newToken);
        token.value = newToken;
    }

    const setAuth = (newAuth) => {
        auth.value = newAuth;
    }

    //函数,移除token的值
    const removeToken = () => {
        token.value = ''
        auth.value = -1;
        return true;
    }

    //得到token
    const getToken = () => {
        return token.value;
    };

    //得到auth
    const getAuth = () => {
        return auth.value;
    };

    return {
        token, setToken, removeToken, getToken, auth, setAuth, getAuth
    }
}, {
    persist: true//持久化存储
});